package ar.com.cema.methodology.analyzer.services.repository.impl;

import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ar.com.cema.methodology.analyzer.model.Person;
import ar.com.cema.methodology.analyzer.model.Survey;
import ar.com.cema.methodology.analyzer.services.persistence.SimpleDAO;
import ar.com.cema.methodology.analyzer.services.repository.SurveyRepository;

@Repository
public class SurveyRepositoryImpl implements SurveyRepository {
	
	@Autowired
	private SimpleDAO simpleDAO;
	
	@Override
	public Survey findSurveyFrom(Person person) {
		return (Survey) simpleDAO.createCriteria(Survey.class).add(Restrictions.eq("person.email", person.getEmail())).uniqueResult();
	}

	public void setSimpleDAO(SimpleDAO simpleDAO) {
		this.simpleDAO = simpleDAO;
	}

	@Override
	public Survey save(Survey survey) {
		return (Survey) simpleDAO.save(survey);
	}

	@Override
	public Survey update(Survey survey) {
		simpleDAO.update(survey);
		return survey;
	}
}